package com.tao.checkcode.controller;



import com.tao.checkcode.model.CheckCodeParamsDto;
import com.tao.checkcode.model.CheckCodeResultDto;
import com.tao.checkcode.service.CheckCodeService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.M
 * @version 1.0
 * @description 验证码服务接口
 * @date 2022/9/29 18:39
 */
@Tag(name = "验证码服务接口")
@RestController
public class CheckCodeController {

    @Autowired
    private CheckCodeService picCheckCodeService;


    @Operation(summary = "生成验证信息")
    @PostMapping(value = "/pic")
    public CheckCodeResultDto generatePicCheckCode(CheckCodeParamsDto checkCodeParamsDto){
        return picCheckCodeService.generate(checkCodeParamsDto);
    }

    @Operation(summary="校验")
    @Parameters(value = {
            @Parameter(name = "name", description = "业务名称", required = true, in = ParameterIn.QUERY),
            @Parameter(name = "key", description = "验证key", required = true, in = ParameterIn.QUERY),
            @Parameter(name = "code", description = "验证码", required = true, in = ParameterIn.QUERY)
    })
    @PostMapping(value = "/verify")
    public Boolean verify(String key, String code){
        Boolean isSuccess = picCheckCodeService.verify(key,code);
        return isSuccess;
    }
}
